package cc.monggo.service.impl;

import java.util.Date;

import org.springframework.stereotype.Service;

import cc.monggo.common.AbstractBaseService;
import cc.monggo.domain.BaseUser;
import cc.monggo.domain.XThirdUser;
import cc.monggo.service.RegisterService;
import cc.monggo.utils.EncrypTool;

@Service
public class RegisterServiceImpl extends AbstractBaseService implements
		RegisterService {

	@Override
	public BaseUser insertThirdUser(XThirdUser xThirdUser, BaseUser baseUser) {
		Date date = new Date();

		// 插入用户记录
		baseUser.setPassword(EncrypTool.encodeMD5(baseUser.getPassword()));
		baseUser.setAddTime(date);
		Long userId = baseUserDAO.insert(baseUser);

		// 插入第三方账号
		xThirdUser.setAddTime(date);
		xThirdUser.setUserId(userId);
		xThirdUserDAO.insertRecord(xThirdUser);

		// 返回
		baseUser.setUserId(userId);
		return baseUser;
	}

	@Override
	public XThirdUser selectByThirdIdAndType(String thirdId, String type) {
		return xThirdUserDAO.selectByThirdIdAndType(thirdId, type);
	}

}
